import type {
  KnowledgeParams,
  KnowledgePage,
  PageParms,
  DoctorPage,
  FollowType,
  TopDep,
  Image,
  ConsultOrderPreData,
  ConsultOrderPreParams,
  PartialConsult,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
} from '@/types/consult'
import { request } from '@/utils/request'

export const getKnowledgeList = (params: KnowledgeParams) => {
  return request<KnowledgePage>('/patient/home/knowledge', 'GET', params)
}
export const getDoctorList = (params: PageParms) => {
  return request<DoctorPage>('/home/page/doc', 'GET', params)
}
export const followOrUnFollow = (id: string, type: FollowType = 'doc') => {
  return request('/like/', 'POST', { id, type })
}
export const getAllDep = () => {
  return request<TopDep[]>('/dep/all', 'GET')
}
export const uploadImage = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  return request<Image>('/upload', 'POST', formData)
}
export const getConsultOrderPre = (params: ConsultOrderPreParams) => {
  return request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)
}
export const createConsultOrder = (data: PartialConsult) => {
  return request<{ id: string }>('/patient/consult/order', 'POST', data)
}
export const getOrderPayUrl = (params: {
  orderId: string
  paymentMethod: 0 | 1
  payCallback: string
}) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)
}
export const getOrderDeatil = (orderId: string) => {
  return request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })
}
export const getPrescriptionDetail = (id: string) => {
  return request<{ url: string }>(`/patient/consult/prescription/${id}`, 'GET')
}
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => {
  return request('/patient/order/evaluate', 'POST', data)
}
export const getConsultOrderList = (params: ConsultOrderListParams) => {
  return request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)
}
export const cancelOrder = (id: string) => {
  return request(`/patient/order/cancel/${id}`, 'PUT')
}
export const deleteOrder = (id: string) => {
  return request(`/patient/order/${id}`, 'DELETE')
}
